
function openAddProjectMember() {
    $("#myModal").modal();
}
function deleteProjectMember() {
    var url ="/project/deleteProjectMember";
    var arrSelections =$("#dataTable").bootstrapTable('getSelections');
    if(arrSelections.length <=0){
        Ewin.alert("必须选择一条数据操作");
        return;
    }
    if(arrSelections.length >1){
        Ewin.alert("只能选择一个成员删除");
        return;
    }
    var userId =arrSelections[0].id;
    var projectId=$("#projectId").val();
    Ewin.confirm({message: "确认要删除该项目成员吗？"}).on(function (e) {
        if (!e) {
            return;
        }
        $.ajax({
            url:url,
            method:"post",
            data:{
                userId:userId,
                projectId:projectId
            },success:function (result) {
                if(result.success){
                    $("#dataTable").bootstrapTable("refresh");
                }else {
                    Ewin.alert(result.msg);
                }
            }
        })
    });


}
function submitProjectMember() {
    var url ="/project/addProjectMember";
    var userId =$("#userId").val();
    var projectId=$("#projectId").val();
    $.ajax({
        url:url,
        method:"post",
        data:{
            userId:userId,
            projectId:projectId
        },success:function (result) {
            if(result.success){
                $("#myModal").modal("hide");
                $("#dataTable").bootstrapTable("refresh");
            }else {
                Ewin.alert(result.msg);
            }
        }
    })
}
function param(params) {
    var obj = {
        pageSize: params.limit,
        pageNum: (params.offset / params.limit) + 1,
        projectId:$("#projectId").val()
    };
    return obj;
}
function initSelectUser(){
    var url ="/user/userList";
    $.ajax({
        url:url,
        method:"get",
        beforeSend:function(){
            $("#userId").empty();
        },
        success:function (result) {
            if(result.success){
                var userList =result.obj;
                userList.forEach(function (user) {
                    var option ="<option value='"+user.id+"'>"+user.text+"</option>"
                    $("#userId").append(option);
                })
                $("#userId").select2();
            }else {
                Ewin.alert(result.msg)
            }
        }
    })
}

$(function () {
    initSelectUser();

    var interfaceUrl = "/project/getProjectMember";
    $("#dataTable").bootstrapTable({
        url: interfaceUrl,
        method: "get",
        pageNumber: 1,
        pageSize: 10,
        pageList: [10, 20, 30, 40, 50],
        pagination: true,
        sidePagination: "server",
        cache: false,
        queryParams: param,
        height: 500,
        toolbar: "#toolbar",//这里面需要用到jquery的选择器
        paginationPreText: "上一页",
        paginationNextText: "下一页",
        striped: true,
        showRefresh: true,
        clickToSelect: true,
        sortable: false,
        sortOrder: "asc",
        columns: [
            {
                checkbox: true
            },
            {
                "title": "用户id",
                "field": "id"
            },
            {
                "title": "用户名",
                "field": "userName"
            }
        ]
    })
});